package com.fh.Thread_Exercise;
/*
1.主线程每隔1s，输出hi，一共10次
2.当输出到hi5时，启动一个子线程（要求实现Runnable），每隔1s输出hello，等该线程输出10次hello后，退出
3.主线程继续输出hi，直到主线程退出
4.如图，完成代码其实线程插队..
 */

public class Exercise01 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new T1());
        for (int i = 0;i<10;i++){
            System.out.println("hi"+"-"+i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(i == 5){
                thread.start();
                thread.join();
            }
        }
    }
}
class T1 implements Runnable{
    private int count = 0;
    @Override
    public void run() {
        for (int i = 0;i<10;i++){
            System.out.println("hello");
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
